'''
Created on 07/06/2010

@author: Will
'''
from pyglet.sprite import Sprite
from utils import ImageCache

class CrossHair(Sprite):

    def __init__(self,batch):
        
        self.imagem = ImageCache.getImage("crosshair.png")
        self.imagem.anchor_x = self.imagem.width/2
        self.camera = None
        self.window = None
        self.dead = False
        self.imagem.anchor_y = self.imagem.height/2
        self.mousePos = (0,0)
        super(CrossHair,self).__init__(self.imagem, 0,0,batch=batch)
        
    def tick(self,keyboard):
        ratio = self.camera.zoom*(2)/self.window.height
        self.x = self.camera.x +(self.mousePos[0] - self.window.width/2)* ratio
        self.y = self.camera.y +(self.mousePos[1] - self.window.height/2)* ratio
        
    def setCamera(self,cam):
        self.camera = cam
        
    def getPosition(self):
        return self.x,self.y
    
    def setWindow(self,cam):
        self.window = cam
        
    def on_mouse_motion(self, x, y, dx, dy):
        self.mousePos = (x,y)   


    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        self.mousePos = (x,y)

    def on_mouse_press(self, x, y, button, modifiers):
        pass

    def on_mouse_scroll(self,x, y, scroll_x, scroll_y):
        pass
